package com.itheima.service.impl;

import com.itheima.dao.UserDao;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service("userService")
public class UserServiceImpl implements UserService {

    @Value("张三")
    private String name;

    @Value("23")
    private int age;

    @Autowired
    @Qualifier("userDao")
    /*了解; 根本不用
    @Resource(type=UserDao.class) //按照类型注入对象
    @Resource(name="userDaoImpl") //按照名称注入对象*/
    private UserDao userDao;


    @Value("${jdbc.url}")
    private String url;
    /*public void setName(String name) {
        this.name = name;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    public UserServiceImpl() { }

    public UserServiceImpl(String name, int age, UserDao userDao) {
        this.name = name;
        this.age = age;
        this.userDao = userDao;
    }*/

    @Override
    public void save() {
        System.out.println("获得了jdbc.properties中的url"+url);
        System.out.println("UserServiceImpl save is running..."+name+"..."+age);
        userDao.save();
    }
}